package com.changgou.framework.exception;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @ClassName BaseExceptionHandler
 * @Description 统一异常的处理器
 * @Author 传智播客
 * @Date 13:03 2019/11/10
 * @Version 2.1
 **/
@ControllerAdvice   // 在controller中抛出的异常都能被该类统一解析
public class BaseExceptionHandler {

    @ExceptionHandler(value = {Exception.class})
    @ResponseBody
    public Result error(Exception e){
        e.printStackTrace();
        return new Result(false, StatusCode.ERROR, e.getMessage());
    }
}
